#ifndef WIDGET_H
#define WIDGET_H
#include"tcpserver.h"
#include <QWidget>
#include <QTcpServer>
#include <QTcpSocket>
#include <QByteArray>
#include <QMap>
#include <QCloseEvent>
#include <QUdpSocket>

QT_BEGIN_NAMESPACE
namespace Ui
{
    class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    enum TAB_TYPE {
        TCP_SERVER,
        TCP_CLIENT,
        UDP_SERVER,
        UDP_CLIENT
    };
    // 服务端的
    // QTcpServer *tcpServer;
    // QMap<QString, QTcpSocket*> clientTcpSocketMap;

    TcpServer *tcpServer;

    // 客户端的
    QTcpSocket *tcpSocket;

    QUdpSocket *udpServerSocket;
    QUdpSocket *udpClientSocket;

public slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void do_TcpServerRecvMessage(QString source, QByteArray &data);

    void on_pushButton_3_clicked();
    void do_listenSuccess(int port);
    void do_listenFailed(QString errMsg);
signals:
    void do_write(const QString &msg);
private:
    Ui::Widget *ui;

    // QWidget interface
protected:

};
#endif // WIDGET_H
